package com.example.demo.demos.现场调查;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.RowRenderData;
import com.deepoove.poi.data.Rows;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.example.demo.demos.web.DetailTablePolicy;

import java.io.IOException;
import java.util.*;

/**
 * @author Administrator
 * @describe: TODO
 * @date 2025/2/19
 */
public class MyDemo {

    public static void main(String[] args) {

        String resource = "D:\\poi-tl\\word\\demo\\src\\main\\resources\\现场调查记录表.docx";
        try {
            /*文本*/
            JSONObject map = new JSONObject();
            map.put("no1", "用人单位名称");
            map.put("no2", "检测任务号");
            map.put("no3", "调查人");
            map.put("no4", "用人单位陪同人");
            map.put("no5", "2025年 02月17日");

            map.put("no6", "用人单位");
            map.put("no7", "单位注册地址");
            map.put("no8", "工作场所地址");
            map.put("no9", "统一社会信用代码");
            map.put("no10", "2025年 02月17日");
            map.put("no11", "所属行业");
            map.put("no12", "经济类型");
            map.put("no13", "企业规模");
            map.put("no14", "法定代表人");
            map.put("no15", "管理联系人");
            map.put("no16", "联系人电话");
            map.put("no17", "联系人邮箱");
            map.put("no18", "在册职工人数");
            map.put("no19", "劳务派遣人员数量");
            // -------------主要原辅材料情况---------------------
            List<Map<Object,Object>> rows = new ArrayList<>();

            Map<Object,Object> row = new HashMap<>();
            row.put("rows1", "钢材");
            row.put("rows2", "8.8万件");
            row.put("rows3", "固态");
            row.put("rows4", "铁");
            row.put("rows5", "生产车间/机械冲压工/电焊工");

            rows.add(row);
            rows.add(row);
            rows.add(row);
            rows.add(row);
            map.put("rows", rows);

            // -------------主要中间产物情况---------------------
            List<Map<Object,Object>> interprods = new ArrayList<>();

            Map<Object,Object> interprod = new HashMap<>();
            interprod.put("interprods1", "--以下空白--");
            interprod.put("interprods2", "");
            interprod.put("interprods3", "");
            interprod.put("interprods4", "");
            interprod.put("interprods5", "");

//            interprods.add(interprod);
//            interprods.add(interprod);
//            interprods.add(interprod);
            interprods.add(interprod);
            map.put("interprods", interprods);
            // -------------主要产品情况---------------------
            List<Map<Object,Object>> prducts = new ArrayList<>();

            Map<Object,Object> prduct = new HashMap<>();
            prduct.put("prducts1", "填缝剂");
            prduct.put("prducts2", "7000吨");
            prduct.put("prducts3", "固态");
            prduct.put("prducts4", "袋装");

            prducts.add(prduct);
            prducts.add(prduct);
            prducts.add(prduct);
            prducts.add(prduct);
            map.put("prducts", prducts);

            // -------------要生产设备情况---------------------
            List<Map<Object,Object>> devices = new ArrayList<>();

            Map<Object,Object> device = new HashMap<>();
            device.put("device1", "填缝剂搅拌线");
            device.put("device2", "--");
            device.put("device3", "5");
            device.put("device4", "3");
            device.put("device5", "一车间/班长");

            devices.add(device);
            devices.add(device);
            devices.add(device);
            devices.add(device);
            map.put("devices", devices);


            // -------------职业病防护设施设置和运行情况---------------------
            List<Map<Object,Object>> zybffs = new ArrayList<>();

            Map<Object,Object> zybff = new HashMap<>();
            zybff.put("zybff1", "一车间");
            zybff.put("zybff2", "投料");
            zybff.put("zybff3", "上吸式排风罩");
            zybff.put("zybff4", "防尘");
            zybff.put("zybff5", "1");
            zybff.put("zybff6", "1");

            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            zybffs.add(zybff);
            map.put("zybffs", zybffs);



            // -------------职业病防护用品配置和使用情况---------------------
            List<Map<Object,Object>> fhyps = new ArrayList<>();

            Map<Object,Object> fhyp = new HashMap<>();
            fhyp.put("fhyp1", "呼吸");
            fhyp.put("fhyp2", "防尘口罩");
            fhyp.put("fhyp3", "保为康");
            fhyp.put("fhyp4", "9600");
            fhyp.put("fhyp5", "一车间");
            fhyp.put("fhyp6", "班长");
            fhyp.put("fhyp7", "破损更换");

            fhyps.add(fhyp);
            fhyps.add(fhyp);
            fhyps.add(fhyp);
            fhyps.add(fhyp);
            map.put("fhyps", fhyps);

            // -------------检测岗位的劳动定员和作业情况---------------------
            List<Map<Object,Object>> lddgs = new ArrayList<>();

            Map<Object,Object> lddg = new HashMap<>();
            lddg.put("lddg1", "一车间");
            lddg.put("lddg2", "生产工");
            lddg.put("lddg3", "4");
            lddg.put("lddg4", "4");
            lddg.put("lddg5", "投料工位投料工作");
            lddg.put("lddg6", "②");
            lddg.put("lddg7", "一班制");
            lddg.put("lddg8", "8.0,6,48.0");
            lddg.put("lddg9", "08:00-12:00\n13:30-17:30");
            lddg.put("lddg10", "水泥粉尘（呼尘），水泥粉尘（总尘），噪声");
            lddg.put("lddg11", "--");
            lddg.put("lddg12", "②");


            lddgs.add(lddg);
            lddgs.add(lddg);
            lddgs.add(lddg);
            lddgs.add(lddg);
            lddgs.add(lddg);
            lddgs.add(lddg);
            lddgs.add(lddg);
            lddgs.add(lddg);
            lddgs.add(lddg);
            lddgs.add(lddg);
            lddgs.add(lddg);
            lddgs.add(lddg);
            lddgs.add(lddg);
            lddgs.add(lddg);
            lddgs.add(lddg);
            map.put("lddgs", lddgs);

            // 2.非浓度或强度稳定岗位的详细劳动者接触情况
            RowRenderData ldjc = Rows.of("鲁仲、高中坤", "一车间", "生产工", "--","投料工位","投料工作","水泥粉尘（呼尘），水泥粉尘（总尘），噪声","2.0","每班2次，每次1h").center().create();
            List<RowRenderData> ldjcs = Arrays.asList(ldjc, ldjc, ldjc,ldjc,ldjc,ldjc,ldjc,ldjc,ldjc,ldjc);

            map.put("ldjcs", ldjcs);

            LoopRowTableRenderPolicy hackLoopSameLineTableRenderPolicy = new LoopRowTableRenderPolicy();
            LoopRowTableRenderPolicy hackLoopSameLineTableRenderPolicy1 = new LoopRowTableRenderPolicy(true);
            Configure config = Configure.builder()
                .bind("rows", hackLoopSameLineTableRenderPolicy)
                .bind("interprods", hackLoopSameLineTableRenderPolicy)
                .bind("prducts", hackLoopSameLineTableRenderPolicy)
                .bind("devices", hackLoopSameLineTableRenderPolicy)
                .bind("zybffs", hackLoopSameLineTableRenderPolicy)
                .bind("fhyps", hackLoopSameLineTableRenderPolicy)
                .bind("lddgs", hackLoopSameLineTableRenderPolicy)
                .bind("ldjcs", new LdjcsTablePolicy())
                .build();
            XWPFTemplate.compile(resource,config).render(map).writeToFile("11现场调查记录表.docx");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
